﻿using System;

namespace DimensionsHelper.Common.Metadata;

public readonly struct MetadataArealKey : IEquatable<MetadataArealKey>
{
    private MetadataArealKey(string context, string language, string labelType, string name)
    {
        Context = context.ToUpper();
        Language = language.ToUpper();
        LabelType = labelType.ToUpper();
        Name = name.ToUpper();
    }

    private string Context { get; }

    private string Language { get; }

    private string LabelType { get; }

    private string Name { get; }


    public static MetadataArealKey Create(string context, string language, string labelType, string name)
    {
        return new MetadataArealKey(context, language, labelType, name);
    }


    public bool Equals(MetadataArealKey other)
    {
        return other.Context.Equals(Context, StringComparison.OrdinalIgnoreCase) && 
               other.Language.Equals(Language, StringComparison.OrdinalIgnoreCase) && 
               other.Name.Equals(Name, StringComparison.OrdinalIgnoreCase) &&
               other.LabelType.Equals(LabelType, StringComparison.OrdinalIgnoreCase);
    }

    public override bool Equals(object? obj)
    {
        return obj is MetadataArealKey key && Equals(key);
    }

    public override int GetHashCode()
    {
        return HashCode.Combine(Context, Language, Name);
    }

    public static bool operator ==(MetadataArealKey left, MetadataArealKey right)
    {
        return left.Equals(right);
    }

    public static bool operator !=(MetadataArealKey left, MetadataArealKey right)
    {
        return !(left == right);
    }
}